package com.hl.card.award.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hl.card.modular.packBack.service.ISalesDivisionService;
import com.hl.card.award.service.IRewardByTrans;
import com.hl.card.award.service.IUserRewardByTrans;
import com.hl.card.common.remote.user.RemoteUser;
import com.hl.card.common.remote.user.RemoteUserService;
import com.hl.card.common.util.DateUtils;
import com.hl.card.common.util.ResponseObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * java类简单作用描述
 *
 * @ProjectName: distdev
 * @Package: com.hl.card.modular.pack.service.impl
 * @ClassName: ${TYPE_NAME}
 * @Description: java类作用描述
 * @Author: 作者姓名
 * @CreateDate: 2018/7/9 17:41
 * @UpdateUser: Neil.Zhou
 * @UpdateDate: 2018/7/9 17:41
 * @UpdateRemark: The modified content
 * @Version: 1.0
 * <p>Copyright: Copyright (c) 2018</p>
 */
@Service
public class UserRewardByTransImpl implements IUserRewardByTrans {



    private static final Logger logger = LoggerFactory.getLogger(UserRewardByTransImpl.class);

    @Autowired
    private RemoteUserService remoteUserService;

    @Autowired
    ISalesDivisionService iSalesDivisionService;

    @Autowired
    private IRewardByTrans rewardByTrans;

    @Value("${dismemberapply.ka_ip}")
    private String cpc_ip;

    public ResponseObject userReward(String userId) {
        System.out.println("开始领取老会员福利");
        JSONObject jsonObject=remoteUserService.findSsoUserByUserId(userId);
        RemoteUser remoteUser=null;
        ResponseObject reObj=new ResponseObject();
        reObj.setErroCode(1);
        reObj.setData("无效用户id");
        if (jsonObject.get("code").equals("0")) {
            JSONObject userObj = (JSONObject) jsonObject.get("user");
            remoteUser = JSON.parseObject(userObj.toJSONString(), RemoteUser.class);
            Date elder = DateUtils.strToDate("2018-06-25 12:00:00");
            reObj.setData("非老用户");
            if (remoteUser.getCreateTime() == null || remoteUser.getCreateTime().before(elder)) {//老用户
                reObj= rewardByTrans.reward(userId, "LHYFL");
            }

        }
        return reObj;
    }
    public ResponseObject checkUserReward(String userId) {
        return rewardByTrans.checkReward(userId, "LHYFL");
    }


}
